package com.doubao.auth;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 认证服务主应用程序类
 *
 * @author yourname
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.doubao.auth.client")
@ComponentScan(basePackages = {"com.doubao.auth", "com.doubao.common"})
@MapperScan("com.doubao.auth.mapper")
@Slf4j
public class DoubaoAuthApplication {

    /**
     * 应用入口方法
     *
     * @param args 命令行参数
     * @throws UnknownHostException 如果无法确定本地主机
     */
    public static void main(String[] args) throws UnknownHostException {
        // 添加系统属性以启用bootstrap
        System.setProperty("spring.cloud.bootstrap.enabled", "true");

        ConfigurableApplicationContext application = SpringApplication.run(DoubaoAuthApplication.class, args);
        Environment env = application.getEnvironment();
        String protocol = "http";

        log.info("\n----------------------------------------------------------\n\t" +
                        "应用 '{}' 已成功启动! 访问URLs:\n\t" +
                        "本地: \t\t{}://localhost:{}{}\n\t" +
                        "外部: \t\t{}://{}:{}{}\n\t" +
                        "环境: \t{}\n\t" +
                        "Nacos服务器: \t{}\n" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                protocol,
                env.getProperty("server.port"),
                env.getProperty("server.servlet.context-path", ""),
                protocol,
                InetAddress.getLocalHost().getHostAddress(),
                env.getProperty("server.port"),
                env.getProperty("server.servlet.context-path", ""),
                env.getProperty("spring.profiles.active"),
                env.getProperty("spring.cloud.nacos.config.server-addr"));
    }
}
